package org.bspv.pharma.business.impl;

import java.util.List;

import org.bspv.pharma.business.ManagementBusinessService;
import org.bspv.pharma.common.exception.EntityNotFoundException;
import org.bspv.pharma.manager.DrugstoreManager;
import org.bspv.pharma.manager.TypeOfSupplyManager;
import org.bspv.pharma.model.Drugstore;
import org.bspv.pharma.model.TypeOfSupply;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 
 * @author guillaume
 * 
 */
@Service(value = "managementBusinessService")
public class ManagementBusinessServiceImpl implements ManagementBusinessService {

    /**
     * Logger.
     */
    private final static Logger LOGGER = LoggerFactory.getLogger(ManagementBusinessServiceImpl.class);

    /** Service basique des pharmacies. */
    @Autowired
    private DrugstoreManager drugstoreManager;
    /** Service basique des types de fourniture. */
    @Autowired
    private TypeOfSupplyManager typeOfSupplyManager;

    // //////////////////////////////////////////////////////////////////////////////////////////////
    // METHODES METIER POUR LES PHARMACIES //
    // //////////////////////////////////////////////////////////////////////////////////////////////

    /**
     * {@inheritDoc}
     */
    @Override
    public List<Drugstore> findAllValidDrugstores() {
        return drugstoreManager.findAllValidDrugstores();
    }

    // //////////////////////////////////////////////////////////////////////////////////////////////
    // METHODES METIER POUR LES FOURNITURES //
    // //////////////////////////////////////////////////////////////////////////////////////////////

    /**
     * {@inheritDoc}
     */
    @Override
    public List<TypeOfSupply> findAllValidTypeOfSupplies(String drugstoreId) throws EntityNotFoundException {
        Drugstore drugstore = drugstoreManager.findById(drugstoreId);
        if (drugstore == null) {
            LOGGER.error("La pharmacie (code : {}) est inexistante", drugstoreId);
            throw new EntityNotFoundException("Pharmacie inexistante");
        }
        return typeOfSupplyManager.findAllValidSupplies(drugstore);
    }

    // //////////////////////////////////////////////////////////////////////////////////////////////
    // ACCESSEURS //
    // //////////////////////////////////////////////////////////////////////////////////////////////


    /**
     * @param drugstoreManager
     *            the drugstoreManager to set
     */
    public void setDrugstoreManager(DrugstoreManager drugstoreManager) {
        this.drugstoreManager = drugstoreManager;
    }

    /**
     * @param typeOfSupplyManager
     *            the typeOfSupplyManager to set
     */
    public void setTypeOfSupplyManager(TypeOfSupplyManager typeOfSupplyManager) {
        this.typeOfSupplyManager = typeOfSupplyManager;
    }

}
